package com.epam.cdp.jpa.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@Data
@ToString(exclude = "books", callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Entity
@NamedQuery(name = "Author.allBooksForAuthor", query = "SELECT a.books FROM Author a WHERE a.id = :id")
public class Author extends BaseEntity {

    private static final transient long serialVersionUID = 1L;
    
    private String firstName;
    private String lastName;
    
    @ManyToMany(targetEntity = Book.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, mappedBy = "authors")
    private List<Book> books;
}
